<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="企业名称" prop="enterpriseName">
        <el-input
          v-model="queryParams.enterpriseName"
          placeholder="请输入企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开始日期" prop="startDate">
        <el-date-picker clearable
          v-model="queryParams.startDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择开始日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束日期" prop="endDate">
        <el-date-picker clearable
          v-model="queryParams.endDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


  <el-tabs v-model="status" type="card" @tab-click="handleClick">
    <el-tab-pane label="全部" name=""></el-tab-pane>
    <el-tab-pane label="待支付" name="1"></el-tab-pane>
    <el-tab-pane label="已支付" name="2"></el-tab-pane>
    <el-tab-pane label="已取消" name="3"></el-tab-pane>
  </el-tabs>

    <el-table v-loading="loading" :data="platformRightsOrderList">
      <!-- <el-table-column :formatter="defaultTableColumnDate" label="ID" align="center" prop="id" /> -->
      <el-table-column :formatter="defaultTableColumnDate" label="序号" align="center" type="index" />
      <el-table-column :formatter="defaultTableColumnDate" label="订单编号" align="center" prop="orderNumber" />
      <el-table-column :formatter="defaultTableColumnDate" label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :formatter="defaultTableColumnDate" label="支付时间" align="center" prop="payTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :formatter="defaultTableColumnDate" label="订单金额" align="center" prop="amount" />
      <el-table-column :formatter="defaultTableColumnDate" label="套餐类型" align="center" prop="rightsName" />
      <el-table-column :formatter="defaultTableColumnDate" label="企业名称" align="center" prop="enterpriseName" />
      <el-table-column :formatter="defaultTableColumnDate" label="手机号码" align="center" prop="phone" />
      <el-table-column :formatter="defaultTableColumnDate" label="支付方式" align="center" prop="payType">
        <template slot-scope="scope">
          {{ payTypeInfo[scope.row.payType] }}
        </template>
      </el-table-column>

      <el-table-column :formatter="defaultTableColumnDate" label="订单状态" align="center" prop="status">
        <template slot-scope="scope">
          {{ statusInfo[scope.row.status] }}
        </template>
      </el-table-column>
      <!-- <el-table-column :formatter="defaultTableColumnDate" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:platformRightsOrder:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:platformRightsOrder:remove']"
          >删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改平台权益订单对话框 -->
    <el-dialog destroy-on-close :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单编号" prop="orderNumber">
          <el-input v-model="form.orderNumber" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="权益id" prop="rightsId">
          <el-input v-model="form.rightsId" placeholder="请输入权益id" />
        </el-form-item>
        <el-form-item label="企业id" prop="enterpriseId">
          <el-input v-model="form.enterpriseId" placeholder="请输入企业id" />
        </el-form-item>
        <el-form-item label="订单金额" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入订单金额" />
        </el-form-item>
        <el-form-item label="支付时间" prop="payTime">
          <el-date-picker clearable
            v-model="form.payTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择支付时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="删除标识 0 正常 1 删除" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标识 0 正常 1 删除" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPlatformRightsOrder, getPlatformRightsOrder, delPlatformRightsOrder, addPlatformRightsOrder, updatePlatformRightsOrder } from "@/api/system/platformRightsOrder";

export default {
  name: "PlatformRightsOrder",
  data() {
    return {
      payTypeInfo: {
        '1': '微信',
        '2': '支付宝',
      },
      statusInfo: {
        '1': '待支付',
        '2': '已支付',
        '3': '已取消',
      },
      status: '',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 平台权益订单表格数据
      platformRightsOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNumber: null,
        rightsId: null,
        enterpriseId: null,
        amount: null,
        payType: null,
        status: null,
        payTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleClick(tab, event) {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 查询平台权益订单列表 */
    getList() {
      this.loading = true;
      listPlatformRightsOrder({...this.queryParams, status: this.status}).then(response => {
        this.platformRightsOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderNumber: null,
        rightsId: null,
        enterpriseId: null,
        amount: null,
        payType: null,
        status: null,
        payTime: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加平台权益订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPlatformRightsOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改平台权益订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePlatformRightsOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPlatformRightsOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除平台权益订单编号为"' + ids + '"的数据项？').then(function() {
        return delPlatformRightsOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/platformRightsOrder/export', {
        ...this.queryParams
      }, `platformRightsOrder_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
